public class Test {

    public int singleNumber(int[] nums) {
        int ans = 0;
        for(int i = 0; i < 32; i++) {
            int sum = 0;
            for(int x : nums) {
                sum += (x >> i) & 1;
            }
            ans |= ((sum % 3) << i);
        }
        return ans;
    }

    public int[] missingTwo(int[] nums) {
        int tmp = 0;
        for(int x : nums) {
            tmp ^= x;
        }
        for(int i = 1; i <= nums.length + 2; i++) {
            tmp ^= i;
        }

        tmp &= -tmp;
        int ret1 = 0, ret2 = 0;
        for(int x : nums) {
            if((x & tmp) == 0) {
                ret1 ^= x;
            } else {
                ret2 ^= x;
            }
        }
        for(int i = 1; i <= nums.length + 2; i++) {
            if((i & tmp) == 0) {
                ret1 ^= i;
            } else {
                ret2 ^= i;
            }
        }

        return new int[]{ret1,ret2};
    }
    public static void main(String[] args) {

    }
}
